/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
/*
 * uniview
 * Copyright (C) Michael J. Beer 2010 <michael.josef.beer@googlemail.com>
 * 
 * uniview is free software: you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * uniview is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License along
 * with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef _POINT_HH_
#define _POINT_HH_

#include <string>
#include <cmath>

namespace uniview {


    class Point {

        public:

            static const int DIMENSION = 3;

            inline static double *newPoint(int m) {
                return new double[Point::DIMENSION];
            };
            
            
            inline static double sqrDistance(double *a, double *b) {
                double coord = a[0] - b[0];
                double sqrSum = coord * coord;
                coord = a[1] - b[1];
                sqrSum += coord * coord;
                coord = a[2] - b[2];
                sqrSum += coord * coord;
                return sqrSum;
            };

            inline static double distance(double *a, double *b) {
                return sqrt(sqrDistance(a, b));
            };

            inline static double *multiply(double *a, double scalar) {
                for(int i = 0; i < Point::DIMENSION; i++) {
                    a[i] *= scalar;
                };
                return a;
            };

            inline static double *add(double *a, double *b) {
                for(int i = 0; i < Point::DIMENSION; i++) {
                    a[i] += b[i];
                };
                return a;      
            };
                        
            static std::string toString(int m, double *p);
    };

};

#endif // _POINT_HH_
    